package com.example.day20_zhongji.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.day20_zhongji.R;
import com.example.day20_zhongji.Sql;
import com.example.day20_zhongji.adapter.SqldAdapter;
import com.example.day20_zhongji.bean.Cardban;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class SqlFragment extends Fragment {


    private RecyclerView mRe;

    public SqlFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_sql, container, false);
        initViews(view);
        return view;
    }

    private void initViews(View view) {
        mRe = view.findViewById(R.id.re);
        mRe.setLayoutManager(new LinearLayoutManager(getContext()));
        mRe.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        Sql sql = new Sql(getContext());
        List<Cardban> query = sql.query();
        SqldAdapter sqldAdapter = new SqldAdapter(getContext(), query);
        mRe.setAdapter(sqldAdapter);
    }
}
